﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using chessLogic;

namespace chessTest
{
    [TestFixture]
    public class testChess
    {
        private Chess chess;
        private FigureMove move;
        [SetUp]
        public void SetUp()
        {
            chess = new Chess();
            move = new FigureMove();
            chess.board.InitialBoard();
            chess.currentGame = new Game();
            chess.currentGame.Moves.AddRange(new string[] { "e4", "a2", "a3" });
        }
        [Test]
        public void testGetOldPosition()
        {
            move.ConvertNotation("e4", chess.board, FigureColor.White);
            Position position = chess.getOldPosition(move);
            Assert.True(chess.board.getFigure(position).Equals(new Pawn(FigureColor.White)));
        }
        [Test]
        public void testMakeMove()
        { 
            move.ConvertNotation("e4",chess.board,FigureColor.White);
            chess.MakeMove(move);
            Assert.True(new None().Equals(chess.board.getFigure(new Position("e2"))));
            Assert.False(new None().Equals(chess.board.getFigure(new Position("e4"))));
        }
        [Test]
        public void testMakeMoveKingCastling()
        {
            move.ConvertNotation("O-O", chess.board, FigureColor.White);
            chess.MakeMove(move);
            Assert.True(chess.board.getFigure(new Position("g1")).Type == FigureType.King);
            Assert.True(chess.board.getFigure(new Position("f1")).Type == FigureType.Rook);
        }
        [Test]
        public void testMakeMoveQueenCastling()
        {
            move.ConvertNotation("O-O-O", chess.board, FigureColor.Black);
            chess.MakeMove(move);
            Assert.True(chess.board.getFigure(new Position("c8")).Type == FigureType.King);
            Assert.True(chess.board.getFigure(new Position("d8")).Type == FigureType.Rook);
        }
        [Test]
        public void testMakeMovePassant()
        {
            chess.board.setFigure(new Position("e5"), new Pawn(FigureColor.White));
            chess.board.setFigure(new Position("d5"), new Pawn(FigureColor.Black));
            move.ConvertNotation("exd6", chess.board, FigureColor.White);
            chess.MakeMove(move);
            Assert.True(chess.board.getFigure(new Position("e5")).Equals(new None()));
            Assert.False(chess.board.getFigure(new Position("d6")).Equals(new None()));
        }
        [Test]
        public void testMakeMovePromotion()
        {
            chess.board.setFigure(new Position("e7"), new Pawn(FigureColor.White));
            move.ConvertNotation("exd8R", chess.board, FigureColor.White);
            chess.MakeMove(move);
            Assert.True(chess.board.getFigure(new Position("e7")).Equals(new None()));
            Assert.True(chess.board.getFigure(new Position("d8")).Equals(new Rook(FigureColor.White)));
        }
        [Test]
        public void testInitialChess()
        {
            move.ConvertNotation("e4", chess.board, FigureColor.White);
            chess.MakeMove(move);
            chess.currentGame.NextMove();
            chess.InitialChess();
            Assert.True(chess.board.getFigure(new Position("e4")).Equals(new None()));
            Assert.AreEqual(0, chess.currentGame.MoveNumber);
        }
        [Test]
        public void testMakeNextMove()
        {
            chess.InitialChess();
            chess.MakeNextMove();
            Assert.True(chess.board.getFigure(new Position("e4")).Equals(new Pawn(FigureColor.White)));
            Assert.True(chess.board.getFigure(new Position("e2")).Equals(new None()));
        }
    }
}
